package com.fxd.cloud.controller;

import com.fxd.cloud.service.PaymentService;
import com.fxd.cloudapicommons.entities.CommonResult;
import com.fxd.cloudapicommons.entities.Payment;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author xudongfu
 * @date 2025/03/09
 */
@RestController
@Slf4j
@RequestMapping("/payment")
public class PaymentController {

    @Resource
    private PaymentService paymentService;


    @PostMapping("/create")
    public CommonResult create(@RequestBody Payment payment) {
        int result = paymentService.create(payment);
        log.info("插入结果: {}", result);
        if (result > 0) {
            return new CommonResult(200, "插入数据库成功",
                    result);
        } else {
            return new CommonResult(444, "失败");
        }
    }

    @GetMapping(value = "/get/{id}")
    public CommonResult getPaymentById(@PathVariable("id") Long id) {
        return new CommonResult(200, "成功", paymentService.getPaymentById(id));
    }

}
